package com.dkd.common.test;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationAttributes;

import java.lang.reflect.AnnotatedElement;

public class AnnotationAttributesBootstrap {

    public static void main(String[] args) {
        AnnotatedElement annotatedElement = SpringBootApplication.class;
        //获取@ComponentScan注解属性独享
        AnnotationAttributes componentScanAttributes = AnnotatedElementUtils
                .getMergedAnnotationAttributes(annotatedElement, ComponentScan.class);
        //获取@SpringBootConfiguration注解属性独享
        AnnotationAttributes springBootConfigurationAttributes = AnnotatedElementUtils
                .getMergedAnnotationAttributes(annotatedElement, SpringBootConfiguration.class);
        print(componentScanAttributes);
        print(springBootConfigurationAttributes);
    }

    private static void print(AnnotationAttributes annotationAttributes) {
        System.out.printf("注解%s属性集合：\n", annotationAttributes.annotationType().getName());
        annotationAttributes.forEach((name, value) -> System.out.printf("\t属性%s:%s\n", name, value));
    }
}
